<?php

namespace app\api\controller;

use think\Controller;

class Search extends Controller
{
    //  //页面分页
    public function page($page ,$size,$success,$message){
        $return = [
            'data' => '',
            'success' => $success,
            'messages' => $message,
            'page' =>$page,
            'size' => $size
        ];
        $data2 = model('Pops')->order('weight asc,update_time desc')->paginate($size, false, [
            'page' => $page,
            'var_page' => 'page'
        ]);
        $data = $data2->toArray();

        if ($page>$data['last_page']) {
            $data = model('Pops')->order('weight asc,update_time desc')->paginate($size, false, [
                'page' => $data['last_page'],
                'var_page' => 'page'
            ]);
            $data = $data->toArray();
            $return['page'] = $data['last_page'];
        }
        $return['data'] = $data['data'];
        $return['total'] = $data['total'];

        $return['page'] = $data['current_page'];
        return $return;
    }
    public function listeSearch(){
        $page = input('get.page');
        $size = input('get.size');
        $return = $this->page($page,$size,true,"查询成功");

        return json($return);
    }
}
